<template>
    <div style="height:100%;width:100%;position:relative;">
        <rm-layout-left :splitwidth=5 :fixsize=300 :minfixsize=50 :maxfixsize=500>
            <template v-slot:fix>
                <div class="left">
                    <div class="middle-tab-bottom">
                        <el-tree :props="treeProps" :load="LoadNode" node-key="locationid" lazy @node-click="NodeClick"
                            @node-contextmenu="RightClick" @node-drop="nodeDrop" :allow-drag="allowDrag"
                            :allow-drop="allowDrop" :highlight-current="true" ref="tree" :render-content="RenderContent"
                            :render-after-expand="true" @current-change="treeCurrentChangeEvent" empty-text="请先选择对应的样本库"
                            draggable @node-drag-start="nodeDragStart" @node-drag-end="nodeDragEnd"
                            :default-expanded-keys="keyList">
                            <!-- :default-expanded-keys="defaultExpandKeys" -->
                            <!-- :default-expand-all="true" -->
                        </el-tree>
                    </div>
                </div>
            </template>
            <div class="right">
                <div class="right-top">
                    <table style="font-size:12px" class="table1style">
                        <tr>
                            <td>样本库</td>
                            <td>
                                <el-select v-model="selLibrID" filterable style="width:100px" @change="SwitchTree">
                                    <el-option v-for="(item, index) in selLibrID_Options" :key="index" :value="item.librid"
                                        :label="item.librname"></el-option>
                                </el-select>
                            </td>
                            <td><b>预计销毁日期</b></td>
                            <td>
                                <el-date-picker v-model="preoutdate" :able="false" type="date" placeholder="选择日期"
                                    value-format="yyyy-MM-dd" style="width:120px;" :clearable="true">
                                </el-date-picker>
                            </td>
                            <!-- <td>
                                <el-checkbox v-model="chkReenter"></el-checkbox>
                            </td> -->

                            <td align="right" colspan="1">
                                <el-checkbox v-model="inorder" true-label="1" false-label="0"
                                    @change="FocusNextPos">纵向</el-checkbox>
                            </td>
                            <td align="right" colspan="1">
                                <el-checkbox style="align:right" true-label="1" false-label="0"
                                    v-model="allowrepeat">允许重复入库</el-checkbox>
                            </td>
                            <td align="right" colspan="1">
                                <el-checkbox v-model="bdefaultChk">记忆归还方式</el-checkbox>
                            </td>
                            <!-- <td align="right" colspan="1">
                                <el-checkbox style="align:right" true-label="1" false-label="0" v-model="allowsendback">允许样本归还</el-checkbox>
                            </td> -->
                            <!-- <td align="right" colspan="1">
                                <el-button icon="el-icon-search" @click.native="btnExpand">展开全部节点</el-button>
                            </td>
                            <td align="right" colspan="1">选中测试</td>
                            <td>
                                <el-input icon="el-icon-search" @keyup.enter.native="currentTest" v-model="currenttext"></el-input>
                            </td> -->
                            <td style="float:right"><b style="color:red;font-size:14px;float:right">{{ nowLocNa }}</b></td>
                        </tr>
                    </table>
                </div>
                <div class="right-center">
                    <el-tabs style="height:100%;" type="border-card" @tab-click="handleClick" v-model="tabShowFlag">
                        <el-tab-pane label="扫描入库" name="tabname_smrk">
                            <div class="right-center-smrk-1">
                                <table style="font-size:12px" class="table1style">
                                    <tr>
                                        <td><b>扫描条码</b></td>
                                        <td>
                                            <el-input v-model="txtBarCode" style="width:160px"
                                                @keyup.enter.native="scanPreEvent(txtBarCode)"
                                                @click.native="HightlightPos(txtBarCode)" ref="scaninput"
                                                id="barcodediv"></el-input>
                                        </td>
                                        <td>
                                            <el-button icon="el-icon-position" v-has="'PSYNC'"
                                                @click="savepreoutdate()">保存预销毁日期</el-button>
                                            <el-button icon="el-icon-position" v-has="'PSYNC'"
                                                @click="batchsetpreoutdate()">批量设定预销毁日期</el-button>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div style="height:calc(100% - 38px)">
                                <rm-layout-left splitcolor="#F8F8FF" :splitwidth="5" :fixsize="232">
                                    <template v-slot:fix>
                                        <rm-layout-top splitcolor="#F8F8FF" :splitwidth="5" :fixsize="238">
                                            <template v-slot:fix>
                                                <div style="height:100%;width:100%;">
                                                    <div class="shelf-detail">
                                                        <div v-for="row in selectrow.rownumber" :key="'row' + row"
                                                            :class="['shelf-row', row == 1 ? 'first-row' : '']">
                                                            <!--  -->
                                                            <div v-if="row == 1" style="display:inline-flex;">
                                                                <div class="col-title" v-if="row == 1" style="width: 22px;">
                                                                </div>
                                                                <div class="col-title" v-for="col in selectrow.colnumber"
                                                                    :key="'col' + col">{{ col }}</div>
                                                            </div>
                                                            <div class="nofirst-row">
                                                                <div class="row-title">{{ row }}</div>
                                                                <template v-if="shelfDetail.length > 0">
                                                                    <div :class="['shelf-position', shelfDetail[row - 1][col - 1].inuse != '0' ? shelfDetail[row - 1][col - 1].isselected ? 'shelf-inuse-focus' :
                                                                        'shelf-inuse' : shelfDetail[row - 1][col - 1].isselected ? 'shelf-unuse-focus' : '']"
                                                                        v-for="col in selectrow.colnumber"
                                                                        :key="'col' + col"
                                                                        @mousedown="MouseDown(row, col, $event)"></div>
                                                                </template>
                                                                <template v-else>
                                                                    <div class="shelf-position"
                                                                        v-for="col in selectrow.colnumber"
                                                                        :key="'col' + col"></div>
                                                                </template>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </template>
                                            <el-tabs style="height:100%;" type="card" @tab-click="handleClick"
                                                v-model="scanShowFlag" :tab-position='tabPosition' class="sample-content">
                                                <el-tab-pane label="样本信息" name="smpsample" class="sample-infodata">
                                                    <div class="sample-infodata">
                                                        <span class="sample-title" style="padding-top:12px">条码号：</span>
                                                        <span class="sample-info"
                                                            style="font-weight:bold;">{{ sampleInfo.smp_barcode }}</span>
                                                    </div>
                                                    <div>
                                                        <span class="sample-title">行：</span>
                                                        <span class="sample-info1"
                                                            style="font-weight:bold;">{{ sampleInfo.posinrow }}</span>
                                                        <span>列：</span>
                                                        <span class="sample-info1"
                                                            style="font-weight:bold;">{{ sampleInfo.posincol }}</span>
                                                    </div>
                                                    <div>
                                                        <span class="sample-title">姓名：</span>
                                                        <span class="sample-info"
                                                            style="font-weight:bold;">{{ sampleInfo.pat_name }}</span>
                                                    </div>
                                                    <div>
                                                        <span class="sample-title">病人号：</span>
                                                        <span class="sample-info">{{ sampleInfo.pat_no }}</span>
                                                    </div>
                                                    <div>
                                                        <span class="sample-title">样本类型：</span>
                                                        <span class="sample-info">{{ sampleInfo.smp_type }}</span>
                                                    </div>
                                                    <div>
                                                        <span class="sample-title">登记编号：</span>
                                                        <span class="sample-info">{{ sampleInfo.smp_registerid }}</span>
                                                    </div>
                                                    <div>
                                                        <span class="sample-title">样本架：</span>
                                                        <span class="sample-info">{{ sampleInfo.shelfid }}</span>
                                                    </div>
                                                    <div>
                                                        <span class="sample-title">申请项目</span>
                                                        <span class="sample-info">
                                                            <el-input type="textarea" rows="3" style="font-weight:bold;"
                                                                v-model="sampleInfo.smp_comments" disabled></el-input>
                                                        </span>
                                                    </div>
                                                </el-tab-pane>
                                                <el-tab-pane label="归还记录" name="qlendback">
                                                    <div class="lendbacktab-top"
                                                        :style="{ height: OtherShow ? '97px' : '34px' }">
                                                        <table style="font-size:12px" class="table2style">
                                                            <tr v-show="OtherShow">
                                                                <td>开始日期</td>
                                                                <td>
                                                                    <el-date-picker v-model="lbstartdt" :able="false"
                                                                        type="datetime" placeholder=""
                                                                        value-format="yyyy-MM-dd" style="width: 151px;"
                                                                        :clearable="false" prefix-icon="none">
                                                                    </el-date-picker>
                                                                </td>
                                                            </tr>
                                                            <tr v-show="OtherShow">
                                                                <td>结束日期</td>
                                                                <td>
                                                                    <el-date-picker v-model="lbenddt" type="datetime"
                                                                        :able="false" placeholder=""
                                                                        value-format="yyyy-MM-dd" style="width: 151px;"
                                                                        clearable prefix-icon="none">
                                                                    </el-date-picker>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    <el-link :underline="false" style="font-size:12px"
                                                                        @click="otherShow()">{{ OtherShow ? "收起▲" : "展开▼"
                                                                        }}</el-link>
                                                                </td>
                                                                <td colspan="2">
                                                                    <el-button icon="el-icon-search" type="primary"
                                                                        v-has="'PINQUERY'"
                                                                        @click="btnQueryLendBack()">查询</el-button>
                                                                    <el-button icon="el-icon-printer"
                                                                        @click="btnLBPrint()">打印</el-button>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </div>
                                                    <div class="lendbacktab-center"
                                                        :style="{ top: OtherShow ? '97px' : '34px' }">
                                                        <vxe-table :bLoading="bLoading" :data.sync="qlendbackdata" border
                                                            fit height="auto" header-align="center" highlight-current-row
                                                            highlight-hover-row ref="qLendBackXTable" resizable
                                                            show-header-overflow="tooltip" show-overflow="tooltip"
                                                            size="mini" stripe :key="qlbKey">
                                                            <vxe-table-column field="smp_barcode" title="条码号"
                                                                width="100px"></vxe-table-column>
                                                            <vxe-table-column field="remarks" title="架位信息"
                                                                width="200px"></vxe-table-column>
                                                            <vxe-table-column field="createdate" title="归还日期" width="140px"
                                                                align="center"></vxe-table-column>
                                                        </vxe-table>
                                                    </div>

                                                </el-tab-pane>
                                            </el-tabs>
                                        </rm-layout-top>
                                    </template>
                                    <div style="height:100%">
                                        <vxe-table :bLoading="bLoading" :data.sync="locationDetail_Data" border fit
                                            height="auto" header-align="center" highlight-current-row highlight-hover-row
                                            ref="locXTable" resizable show-header-overflow="tooltip" show-overflow="tooltip"
                                            size="mini" stripe :cell-class-name="smrkCellClassName"
                                            @current-change="smrkCurrentChangeEvent" :keyboard-config="keyConfig"
                                            :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, activeMethod: activeMethod, showIcon: false }">
                                            <vxe-table-column field="smp_barcode" title="条形码" width="90px"
                                                align="center"></vxe-table-column>
                                            <vxe-table-column field="preoutdate" title="预销毁日期" width="130px" align="center"
                                                :formatter="['toDateString', 'yyyy-MM-dd']"
                                                :edit-render="{ name: 'input', attrs: { type: 'date' } }"></vxe-table-column>
                                            <vxe-table-column field="posinrow" title="行" width="30px" header-align="center"
                                                align="right"></vxe-table-column>
                                            <vxe-table-column field="posincol" title="列" width="30px" header-align="center"
                                                align="right"></vxe-table-column>
                                            <vxe-table-column field="pat_name" title="病人姓名" width="70px"
                                                align="center"></vxe-table-column>
                                            <vxe-table-column field="smp_comments" title="申请项目"
                                                width="180px"></vxe-table-column>
                                            <vxe-table-column field="pat_no" title="病人号" width="100px"></vxe-table-column>
                                            <vxe-table-column field="smp_type" title="样本类型" width="80px"
                                                align="center"></vxe-table-column>
                                            <vxe-table-column field="quantitystatus" title="样本量状态" width="80px"
                                                align="center"></vxe-table-column>
                                            <vxe-table-column field="description" title="位置说明"
                                                width="100px"></vxe-table-column>
                                            <vxe-table-column field="inusename" title="是否占用" width="70px"
                                                align="center"></vxe-table-column>
                                            <vxe-table-column field="shelfid" title="样本架ID" width="60px"
                                                header-align="center" align="right"></vxe-table-column>
                                            <vxe-table-column field="shelfno" title="样本架编号" width="80px"
                                                header-align="center" align="right"></vxe-table-column>
                                            <vxe-table-column field="smp_registerid" title="登记编号" width="70px"
                                                align="right"></vxe-table-column>
                                            <vxe-table-column field="smp_locationid" title="样本位置" width="70px"
                                                align="right"></vxe-table-column>
                                            <vxe-table-column field="smp_shelfposid" title="样本位置孔位" width="90px"
                                                align="right"></vxe-table-column>
                                        </vxe-table>
                                    </div>
                                </rm-layout-left>
                            </div>
                        </el-tab-pane>
                        <el-tab-pane label="批量入库" name="tabname_plrk">
                            <div class="right-center-plrk-ly-1">
                                <table style="font-size:12px;" class="table1style">
                                    <col style="width: 5%;" />
                                    <col style="width: 13%;" />
                                    <col style="width: 1%;" />
                                    <col style="width: 13%;" />
                                    <col style="width: 5%;" />
                                    <col style="width: 13%;" />
                                    <col style="width: 5%;" />
                                    <col style="width: 13%;" />
                                    <col style="width: 5%;" />
                                    <col style="width: 25%;" />
                                    <tr>
                                        <td align="right">样本日期</td>
                                        <td>
                                            <el-date-picker v-model="searchobj.startdate" :clearable="false" type="date"
                                                placeholder="选择日期" value-format="yyyy-MM-dd"
                                                style="width: 100%;min-width:110px;"> </el-date-picker>
                                        </td>
                                        <td>至</td>
                                        <td>
                                            <el-date-picker v-model="searchobj.enddate" type="date" :clearable="false"
                                                placeholder="选择日期" value-format="yyyy-MM-dd"
                                                style="width: 100%;min-width:110px;"> </el-date-picker>
                                        </td>
                                        <td align="right">样本类型</td>
                                        <td>
                                            <el-select v-model="searchobj.specimen_code"
                                                @dblclick.native="popMultipleChk(searchobj.specimen_code, 'specimen_code', specimenOption, '请选择样本类型')"
                                                filterable clearable style="width:100%;min-width:100px;">
                                                <el-option v-for="(item, index) in specimenOption" :key="index"
                                                    :value="item.data" :label="item.display"></el-option>
                                            </el-select>
                                        </td>
                                        <td align="right">所属病区</td>
                                        <td>
                                            <el-select v-model="searchobj.req_wardno"
                                                @dblclick.native="popMultipleChk(searchobj.req_wardno, 'req_wardno', wardOption, '病区选择')"
                                                style="width: 100%;min-width:110px;" filterable clearable>
                                                <el-option v-for="(item, index) in wardOption" :key="index"
                                                    :value="item.data" :label="item.display"> </el-option>
                                            </el-select>
                                        </td>
                                        <!-- <td colspan="1" align="right">样本来源</td>
                                        <td colspan="1">
                                            <el-select v-model="searchobj.sourcetype" placeholder="请选择" clearable  style="width:100px">
                                                <el-option key="all" label="全部" value="all"></el-option>
                                                <el-option key="0" label="科研" value="0"></el-option>
                                                <el-option key="1" label="检验" value="1"></el-option>
                                            </el-select>
                                        </td> -->
                                        <!-- <td style="color:red">*提示:单击下拉选择，双击弹窗多选。</td> -->
                                    </tr>
                                    <tr>
                                        <td align="right">报告单元</td>
                                        <td colspan="3  ">
                                            <el-select v-model="searchobj.rptunitid"
                                                @dblclick.native="popMultipleChk(searchobj.rptunitid, 'rptunitid', rptunitOption, '请选择报告单元')"
                                                filterable clearable style="width:100%">
                                                <el-option v-for="(item, index) in rptunitOption" :key="index"
                                                    :value="item.data" :label="item.display"></el-option>
                                            </el-select>
                                        </td>
                                        <td align="right">病人类型</td>
                                        <td>
                                            <el-select v-model="searchobj.pat_typecode"
                                                @dblclick.native="popMultipleChk(searchobj.pat_typecode, 'pat_typecode', pattypeOption, '病人类型选择')"
                                                filterable clearable style="width:100%">
                                                <el-option v-for="(item, index) in pattypeOption" :value="item.data"
                                                    :label="item.display" :key="index"></el-option>
                                            </el-select>
                                        </td>
                                        <td align="right">申请科室</td>
                                        <td>
                                            <el-select v-model="searchobj.reqdept"
                                                @dblclick.native="popMultipleChk(searchobj.reqdept, 'reqdept', deptOption, '申请科室选择')"
                                                filterable clearable style="width:100%">
                                                <el-option v-for="(item, index) in deptOption" :key="index"
                                                    :value="item.data" :label="item.display"> </el-option>
                                            </el-select>
                                        </td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td align="right">样本号
                                        </td>
                                        <td>
                                            <el-input size="small" style="width:100%;" placeholder="输入如1,2,5-8等格式"
                                                v-model="searchobj.sampleno"></el-input>
                                        </td>
                                        <td colspan="2" align="right">
                                            审核状态
                                            <el-select v-model="searchobj.rechkflag" placeholder="请选择"
                                                style="width:calc( 100% - 50px )">
                                                <el-option key="all" label="全部" value="all"></el-option>
                                                <el-option key="0" label="未审核" value="0"></el-option>
                                                <el-option key="1" label="已审核" value="1"></el-option>
                                            </el-select>
                                        </td>
                                        <td align="right">急诊标志</td>
                                        <td>
                                            <el-select v-model="searchobj.emer_flag" placeholder="请选择" style="width:100%">
                                                <el-option key="" label="全部" value=""></el-option>
                                                <el-option key="0" label="常规" value="0"></el-option>
                                                <el-option key="1" label="加急" value="1"></el-option>
                                            </el-select>
                                        </td>
                                        <td align="right">
                                            <el-checkbox style="width:16%; align:right" true-label="1" false-label="0"
                                                v-model="skipnoempty"></el-checkbox>
                                        </td>
                                        <td colspan="1" align="left">
                                            跳过非空样本架
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="15" align="right">
                                            <el-button icon="el-icon-search" type="primary" v-has="'PINQUERY'"
                                                @click="btnQuery()">查询</el-button>
                                            <el-button @click="btnSetLoc()">分配库位</el-button>
                                            <el-button @click="btnLocSave()" :disabled="!bSetLocOk">批量入库</el-button>
                                            <el-button @click="btnPrint(1)" icon="el-icon-printer"
                                                :disabled="bSetLocOk">打印</el-button>
                                            <el-button @click="btnPrint(2)" icon="el-icon-edit"
                                                :disabled="bSetLocOk">样式设计</el-button>
                                            <!-- <el-button icon="el-icon-refresh-right" @click="btnPrint()" :disabled="bSetLocOk">打印</el-button> -->
                                            <el-button icon="el-icon-upload2" v-has="'PEXPORT'" @click="btnExport()"
                                                :disabled="bSetLocOk">导出</el-button>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="right-center-plrk-ly-2">
                                <vxe-table :loading="bPlrkLoading" :data.sync="qLocData" border height="auto"
                                    header-align="center" highlight-current-row highlight-hover-row ref="AtLocXTable"
                                    resizable show-header-overflow show-overflow size="mini" stripe
                                    :cell-class-name="plrkCellClassName" @current-change="plrkCurrentChangeEvent"
                                    :key="plrkKey">
                                    <vxe-table-column field="locationname" title="冰箱位置" width="120px"></vxe-table-column>
                                    <vxe-table-column field="posinrow" title="行" width="35px"
                                        align="center"></vxe-table-column>
                                    <vxe-table-column field="posincol" title="列" width="35px"
                                        align="center"></vxe-table-column>
                                    <vxe-table-column field="rptunitname" title="报告单元" width="120px"></vxe-table-column>
                                    <vxe-table-column field="sampledate" title="样本日期" align="center" width="80px"
                                        :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                                    <vxe-table-column field="sampleno" title="样本号" width="80px"></vxe-table-column>
                                    <vxe-table-column field="barcode" title="条码号" width="80px"></vxe-table-column>
                                    <vxe-table-column field="specimen_name" title="样本类型" width="80px"></vxe-table-column>
                                    <vxe-table-column field="wardname" title="病区" width="120px"></vxe-table-column>
                                    <vxe-table-column field="deptname" title="申请科室" width="120px"></vxe-table-column>
                                    <vxe-table-column field="pat_typename" title="病人类别" width="60px"
                                        align="center"></vxe-table-column>
                                    <vxe-table-column field="emer_flag" title="急" width="20px">
                                        <template v-slot="{ row, rowIndex, columnIndex }">
                                            <div :key="row.userno + rowIndex + columnIndex" v-if="row.emer_flag == '1'">
                                                <font color="red">急</font>
                                            </div>
                                            <div :key="row.userno + rowIndex + columnIndex" v-else>
                                            </div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="pat_name" title="病人姓名" width="80px"></vxe-table-column>
                                    <vxe-table-column field="pat_no" title="病人号" width="150px"></vxe-table-column>
                                    <vxe-table-column field="pat_sexname" title="性别" width="40px"
                                        align="center"></vxe-table-column>
                                    <vxe-table-column field="pat_agestr" title="年龄" width="50px"></vxe-table-column>
                                    <vxe-table-column field="hospitalname" title="医院代码" width="200px"></vxe-table-column>
                                    <vxe-table-column field="reportid" title="报告ID" width="140px"></vxe-table-column>
                                    <template v-slot:fix>
                                        <div style="font-size:12px;padding-top:3px;background-color:#fff;"><span
                                                style="color:red;margin-left:10px;float:right;">合计: {{ smpCnt }}</span>
                                            <div style="clear:both"></div>
                                        </div>
                                    </template>
                                </vxe-table>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </div>
            </div>
        </rm-layout-left>
        <!-- 移入 -->
        <el-dialog :visible.sync="bShelfAddVisible" width="250px">
            <span slot="title">{{ dlgShelfTitle }}</span>
            <div>架子编号&nbsp;&nbsp;<el-input v-model="dlgMvShelfid" style="width:120px" ref="refMoveShelfid"></el-input>
                <el-popover placement="right" width="250" height="50" trigger="click" v-model="bNullShelfVisible">
                    <el-table height="120" :data="nullShelf_Data" @row-click="nullShelf_Click">
                        <el-table-column width="80" property="shelfno" label="架子编号"></el-table-column>
                        <el-table-column width="40" property="rownumber" label="行"></el-table-column>
                        <el-table-column width="40" property="colnumber" label="列"></el-table-column>
                        <el-table-column width="60" property="posnumber" label="总数"></el-table-column>
                    </el-table>
                    <el-button type="text" class="button" clearable @click="GoToSMP121">前往维护页面</el-button>
                    <el-button slot="reference" v-if="action == 'I'" type="text" class="button" clearable
                        @click="ShowNullShlef">忘记架子编号？点击此处以查询</el-button>
                </el-popover>
            </div>
            <span slot="footer">
                <el-button type="success" @click="btnMoveSave">确定</el-button>
                <el-button type="cancel" @click="bShelfAddVisible = false, dlgMvShelfid = ''">取消</el-button>
            </span>
        </el-dialog>
        <!-- 样本归还 -->
        <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="样本归还" destroy-on-close
            :visible.sync="bLendBackVisible" width="700px">
            <template>
                <div style="height:350px;width:100%;position:relative;">
                    <div class="poppagetop">
                        <!-- <el-button icon="el-icon-switch-upload2" @click="scanLendBack(1)">前往归还</el-button> -->
                        <el-button icon="el-icon-receiving" @click="selMode(2)" v-has="'PEXPORT'">归还样本</el-button>
                        <el-button icon="el-icon-box" @click="selMode(1)" v-has="'PEXPORT'">直接入库</el-button>
                        <el-button icon="el-icon-close" @click="bLendBackVisible = false">取消 </el-button>
                        <el-checkbox style="padding:0 0 0 20px; align:right" v-model="bdefaultChk">归还样本记忆</el-checkbox>
                    </div>
                    <div class="poppagecenter">
                        <vxe-table show-overflow ref="lendBackXTable" height="auto" :data.sync="lendbackdata"
                            show-header-overflow highlight-current-row highlight-hover-row resizable border size="mini"
                            header-align:center>
                            <vxe-table-column type="index" title="NO." width="40"></vxe-table-column>
                            <vxe-table-column field="locationname" title="位置名称" width="100" header-align="center">
                            </vxe-table-column>
                            <vxe-table-column field="posinrow" title="行" width="30px" header-align="center"
                                align="right"></vxe-table-column>
                            <vxe-table-column field="posincol" title="列" width="30px" header-align="center"
                                align="right"></vxe-table-column>
                            <vxe-table-column field="locationid" title="库位ID" width="60" header-align="center">
                            </vxe-table-column>
                            <vxe-table-column field="locationcode" title="库位编号" width="150" header-align="center"
                                class="rowspantop"></vxe-table-column>
                            <vxe-table-column field="shelfno" title="样本架编号" width="80px" header-align="center"
                                align="center"></vxe-table-column>
                            <vxe-table-column field="shelfid" title="样本架ID" width="60px" header-align="center"
                                align="right"></vxe-table-column>
                            <vxe-table-column field="shelfposid" title="样本架孔位" width="80px" header-align="center"
                                align="center"></vxe-table-column>
                        </vxe-table>
                    </div>
                </div>
            </template>
        </el-dialog>
        <!--多选弹窗--->
        <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false"
            :title="multichktitle" :visible.sync="bDlgMultiple" :destroy-on-close="true">
            <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname"
                @change="closedialog"></rm-SqlMultiple>
        </el-dialog>
        <el-dialog :visible.sync="bHelpViible" width="450px">
            <span slot="title">帮助</span>
            <div style="height: 250px; width: 400px">
                <div style="width: 100%; float: left; margin-left: 10px;margin-top:5px">
                    <el-divider content-position="left">重&nbsp;新&nbsp;读&nbsp;取</el-divider>
                    <table>
                        <tr>
                            <td>刷新架位。</td>
                        </tr>
                    </table>
                </div>
                <div style="width: 100%;hetight:40px;float: left; margin-left: 10px;margin-top:5px">
                    <el-divider content-position="left">新增样本架</el-divider>
                    <table>
                        <tr>
                            <td>新增样本架，并自动移入至当前位置。</td>
                        </tr>
                    </table>
                </div>
                <div style="width: 100%;hetight:40px; float: left; margin-left: 10px;margin-top:5px">
                    <el-divider content-position="left">删除样本架</el-divider>
                    <table>
                        <tr>
                            <td>移出样本架，并删除原本的样本架。</td>
                        </tr>
                    </table>
                </div>
                <div style="width: 100%;hetight:40px; float: left; margin-left: 10px;margin-top:5px">
                    <el-divider content-position="left">移入样本架</el-divider>
                    <table>
                        <tr>
                            <td>将同类型的未使用样本架移入。</td>
                        </tr>
                    </table>
                </div>
                <div style="width: 100%;hetight:40px; float: left; margin-left: 10px;margin-top:5px">
                    <el-divider content-position="left">移出样本架</el-divider>
                    <table>
                        <tr>
                            <td>将本样本架移出，若架上有样本则无法删除。</td>
                        </tr>
                    </table>
                </div>
            </div>
            <div style="height: 30px; width: 100%">
                <span slot="footer">
                    <el-button type="success" style=" float: right; " @click="bHelpViible = false">确定</el-button>
                </span>
            </div>
        </el-dialog>
    </div>
</template>


<script type="text/javascript">
import { Promise } from "q";
import { invalid } from "moment";
import XE from "xe-utils"; //引入工具类
// import RmLayoutBottom from '../../../rmcompents/rm-layout-bottom.vue';
export default {
    name: "SMP220",
    data() {
        return {
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
                isArrow: true,
            },
            //*基础组件
            selLibrID: null, //样本库ID
            selLibrID_Options: [], //样本库
            // chkReenter: false, //允许重复录入
            inorder: "0", //纵向
            allowrepeat: "0", //相同条码允许重复入库
            checkvalid: false, //TODO 校验入库条件
            defaultExpandKeys: [0], //!默认样本库
            nowLocNa: "", //显示当前位置
            keyList: [],
            //*树组件
            locationid: -1, //树节点标识
            fatherLocId: -1, //父节点
            isLast: 0, //末节点
            currenttext: "",
            treeProps: {
                //配置选项
                label: "name",
                children: "children",
                isLeaf: "leaf",
            },
            locationList: [],
            maxlv: 0,
            //*tab页
            tabShowFlag: "tabname_smrk",
            //*扫描入库
            txtBarCode: "", //扫描条码
            allowsendback: "1", //允许样本归还
            bLastOk: true,
            backjump: "-1",
            //*扫描入库 - 样本架
            hRowNum: 0,
            hColNum: 0,
            shelfDetail: [],
            moving: { x: -1, y: -1 },
            prepos: { x: -1, y: -1 },
            //*扫描入库 - vxe-table
            smptree_Data: [], //!左侧样本库数据
            location_Data: [], //!单个样本库数据
            locationDetail_Data: [], //单个样本库明细数据
            sampleInfo: {}, //结果选中行
            tabPosition: "top",
            //*扫描入库 - 样本归还
            bLendBackVisible: false,
            lendbackdata: [],
            scanShowFlag: "smpsample",
            lbstartdt: XE.toDateString(XE.getWhatDay(new Date(), -90), "yyyy-MM-dd  hh:mm:ss"),
            lbenddt: null,
            qlendbackdata: [],
            qlbKey: 0,
            OtherShow: true,
            bdefaultChk: false,
            b1LBsample: false,
            selmode: "",
            //*批量入库
            ddlRptUnit: "", //报告单元
            ddlEmer_Flag: "", //急诊标志
            ddlPatTypeCode: "", //病人来源
            ddlRechkFlag: "1", //审核状态
            preoutdate: null, //预计销毁日期
            ddlSmp_StartDt: XE.toDateString(new Date(), "yyyy-MM-dd"), //样本日期-起始
            ddlSmp_EndDt: XE.toDateString(new Date(), "yyyy-MM-dd"), //样本日期-结束
            ddlSpecimenCode: "", //样本类型
            ddlReqDeptNo: "", //申请科室
            ddlRptUnitList: "", //报告单元多选
            ddlReqWardNo: "", //病区
            rechkoptions: [],
            //*批量入库 - 留样 - 查询条件
            searchobj: {
                startdate: XE.toDateString(new Date(), "yyyy-MM-dd"),
                enddate: XE.toDateString(new Date(), "yyyy-MM-dd"),
                // startdate: this.$pub.InitDateTime2(0).datefrom,//样本起始日期
                // enddate: this.$pub.InitDateTime2(0).dateto,//样本结束日期
                specimen_code: "", //样本类型
                req_wardno: "", //所属病区
                rptunitid: "", //报告单元
                sel_pattypecode: "",
                pat_typecode: "", //病人类型
                reqdept: "", //申请科室
                sampleno: "", //样本号
                rechkflag: "1", //审核状态
                emer_flag: "", //急诊标志
                patsex: "",
                germprice: "60.00",
                hospitalcode: "",
                germflag: "",
                medprice: "60.00",
                sourcetype: "all"
            },
            skipnoempty: "1",
            pattypeOption: [],
            deptOption: [],
            wardOption: [],
            hospOption: [],
            doctorOption: [],
            rptunitOption: [],
            rptunitGroupOption: [],
            reportcommOption: [],
            labgroupOption: [],
            specimenOption: [],
            deptgroupOption: [], //deptcomb
            //*批量入库 - vxe-table
            plrkKey: 0, //表格key
            smpCnt: 0, //合计
            bPlrkLoading: false, //批量入库loading
            qLocData: [], //批量入库数据
            oQLocData: [], //备份数据用于重复入库
            //* 批量入库 - Function
            bSetLocOk: false, //库位分配成功标志
            bIsLocDone: false, //已分配库位
            userno: this.$tool.getSession(this.$tool.loginuserno), //当前用户 用于打印
            //*右键菜单
            tpNode: {}, //临时节点，用于右键菜单
            prTpNode: {}, //!父节点
            childNode: {}, //!子节点
            //*右键菜单 - 样本架操作
            dlgShelfTitle: "", //标题
            dlgMvShelfid: "", //样本号ID
            bShelfDelVisible: false, //删除，移出架子类型弹窗
            bNullShelfVisible: false, //查询，样本架
            bShelfAddVisible: false, //新增，移入架子类型弹窗
            nullShelf_Data: [], //移入移出样本架数据
            addShelf_Data: [], //新增样本架查询获取的Data,
            //*右键菜单 - 帮助
            bHelpViible: false,
            //*编辑操作
            action: "M",
            //*多选弹框组件
            option1: [], //多选左
            option2: [], //多选右
            fieldname: "",
            multichktitle: "",
            bDlgMultiple: false, //多选弹框
            //*拖拽
            ////tempdraggingNode:null,//拖拽的临时结点，用于拖拽inner后获取不到parentnode,
            //*其他
            bLoading: false, //载入loading
            bFirstLoading: true, //TODO 首次载入选中行用，update 冗余 待修改
            activeNames: ["1"], //!
            selectrow: {},
        };
    },
    watch: {
        moving(newV, oldV) {
            for (let i = 0; i < this.shelfDetail.length; i++) {
                for (let j = 0; j < this.shelfDetail[i].length; j++) {
                    this.shelfDetail[i][j].isselected = false;
                    // this.tabdata[i][j].isselectedpair = false;
                }
            }
            if (newV.x != -1 && newV.y != -1) {
                //去找成pair的
                this.shelfDetail[newV.x - 1][newV.y - 1].isselected = true;
            }
        },
    },
    created() {
        this.ddlSmp_Library();
        this.smpOption();
        this.initOption();
    },
    mounted() { },
    updated() {
        if (this.bFirstLoading) {
            let currentrow = this.$refs.locXTable.getData(0);
            this.$nextTick(() => {
                if (currentrow) {
                    this.bFirstLoading = false;
                    this.$refs.locXTable.setCurrentRow(currentrow);
                }
            });
        }
    },
    methods: {
        async smpOption() {
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smpOption",
                    },
                });
                if (res) {
                    this.backjump = res;
                    console.log("res", res);
                }
            } catch (e) {
                console.log("error", e);
            }
        },
        selMode(flag) {
            //选择模式 1直接入库 2归还
            if (flag == 1) {
                this.selmode = "1";
                this.scanBarcode();
            } else if (flag == 2) {
                this.selmode = "2";
                this.scanLendBack(this.backjump);
            }
        },
        otherShow() {
            this.qlbKey++;
            this.OtherShow = !this.OtherShow;
        },
        btnExpand() {
            if (this.locationList.length > 0) {
                this.btnReturnExpand(0);
            }
        },
        btnReturnExpand(num) {
            if (num + 1 < this.locationList.length) {
                var node = this.$refs.tree.getNode(this.locationList[num].locationid);
                this.LoadNode(node, "");
                setTimeout(() => {
                    this.btnRefreshLoc(node).then(() => {
                        this.btnReturnExpand(num + 1);
                    });
                }, 500);
            }
        },
        //选中行测试
        currentTest() {
            this.$refs.tree.setCurrentKey(this.currenttext);
            this.NodeClick("", this.$refs.tree.getNode(this.currenttext));
        },
        activeMethod({ row, column }) {
            if (column.property == "preoutdate") {
                return true;
            } else {
                return true;
            }
        },
        //前往维护页面
        GoToSMP121() {
            // this.closeNow()
            //     .then(() => {
            //         this.$router.push("/SMP121");
            //     })
            //     .catch(() => {});

            this.$router.push({ path: "/SMP121" });
        },
        GoToSMP121CLOSE() {
            return new Promise((s, f) => {
                this.bNullShelfVisible = false;
                this.bShelfAddVisible = false;
                this.dlgMvShelfid = "";
                s();
            });
        },
        //切换pre焦点
        FocusNextPos() {
            this.getNextPos(1, 1)
                .then(() => {
                    //todo 实际记录上个位置就行 待优化
                    this.setNextPos();
                })
                .catch(() => { });
        },
        setNextPos() {
            this.shelfDetail.forEach((e) => {
                e.forEach((ee) => {
                    ee.isselected = false;
                });
            });
            if (this.prepos.x > -1 && this.prepos.y > -1) {
                this.shelfDetail[this.prepos.x - 1][this.prepos.y - 1].isselected = true;
            }
            this.bLastOk = true;
        },
        //点击触发文本内容全选
        Focus(event) {
            event.currentTarget.select();
        },
        //获取新增架位
        getNextPos(OX, OY) {
            return new Promise((s, f) => {
                var simpdata = [];
                this.locationDetail_Data.forEach((e) => {
                    simpdata.push({
                        row: XE.toInteger(e.posinrow),
                        col: XE.toInteger(e.posincol),
                    });
                });
                if (simpdata.length > 0) {
                    if (this.inorder == "0") {
                        //横向
                        for (var i = OX; i <= this.selectrow.rownumber; i++) {
                            for (var j = OY; j <= this.selectrow.colnumber; j++) {
                                var firstnull = simpdata.filter((item) => {
                                    return item.row == i && item.col == j;
                                });
                                if (firstnull == "") {
                                    this.prepos = { x: i, y: j };
                                    s();
                                    return false;
                                }
                            }
                        }
                    } else if (this.inorder == "1") {
                        //纵向
                        for (var i = OY; i <= this.selectrow.colnumber; i++) {
                            for (var j = OX; j <= this.selectrow.rownumber; j++) {
                                var firstnull = simpdata.filter((item) => {
                                    return item.row == j && item.col == i;
                                });
                                if (firstnull == "") {
                                    this.prepos = { x: j, y: i };
                                    s();
                                    return false;
                                }
                                // });
                            }
                        }
                    }
                } else if (simpdata.length == 0 && this.selectrow.rownumber > 0 && this.selectrow.colnumber > 0) {
                    this.prepos = { x: 1, y: 1 };
                    s();
                    return false;
                }
                this.prepos = { x: -1, y: -1 };
                s();
                return false;
            });
        },
        //点击样本获取信息
        MouseDown(row, col, ev) {
            var focusrow = {};
            this.moving = { x: row, y: col };
            this.prepos = { x: row, y: col };
            if (this.shelfDetail[row - 1][col - 1].inuse != "0") {
                this.sampleInfo = {};
                this.locationDetail_Data.forEach((e) => {
                    if (e.posinrow == row && e.posincol == col) {
                        focusrow = e;
                        this.$refs.locXTable.scrollToRow(e);
                        this.$refs.locXTable.setCurrentRow(e);
                        this.sampleInfo = e;
                    }
                });
            } else {
                this.$refs.locXTable.setCurrentRow(null);
                this.sampleInfo = {};
            }
        },
        HightlightPos(myValue) {
            if (myValue == "") {
                return false;
            }
            var myField = document.getElementById("barcodediv");
            if (myField.selectionStart || myField.selectionStart === 0) {
                var startPos = myField.selectionStart;
                var endPos = myField.selectionEnd;
                this.$nextTick(() => {
                    myField.selectionStart = 0;
                    myField.selectionEnd = startPos + myValue.length;
                }); // 这句是重点, 圈起来
                myField.focus();
                myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
            }
        },
        scanPreEvent(txtBarCode) {
            // this.$refs.tree.setCurrentKey(txtBarCode);
            // var a = this.$refs.tree.getNode(this.$refs.tree.getCurrentNode());
            var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
            if (reg.test(txtBarCode)) {
                //避免弹窗后按钮回车再次走入这个事件
                return false;
            }
            // event.currentTarget.select();//全选
            if (this.allowsendback == "1") {
                this.lendBackBarcode();
            } else {
                this.scanBarcode();
            }
        },
        //样本归还查询
        async lendBackBarcode() {
            this.lendbackdata = [];
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "lendbackbarcode",
                        barcode: this.txtBarCode,
                    },
                });
                if (res.flag == "1" || res.flag == "2") {
                    console.log("🏂 _ res.flag", res.flag);
                    this.lendbackdata = res.dt;
                    if (res.flag == "1") {
                        this.b1LBsample = true;
                        console.log("323323", this.selmode);
                        if (!this.bdefaultChk || this.selmode == "") {
                            //未勾选 或者未取得默认值，得弹框
                            this.bLendBackVisible = true;
                        } else {
                            this.selMode(XE.toInteger(this.selmode, 0));
                        }
                    } else {
                        this.b1LBsample = false;
                        this.bLendBackVisible = true;
                    }
                    setTimeout(() => {
                        this.$refs.lendBackXTable.setCurrentRow(this.lendbackdata[0]);
                    }, 50);
                } else if (res.flag == "0") {
                    this.scanBarcode();
                }
                this.HightlightPos(this.txtBarCode);
            } catch (e) {
                this.HightlightPos(this.txtBarCode);
                console.log("error", e);
            }
        },
        //样本归还
        async scanLendBack(flag) {
            var row = this.$refs.lendBackXTable.getCurrentRow();
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_labsample_in",
                        barcode: this.txtBarCode,
                        shelfid: row.shelfid,
                        allowrepeat: this.allowrepeat,
                        posinrow: row.posinrow,
                        posincol: row.posincol,
                        inorder: this.inorder,
                        locationid: row.locationid,
                        lendbackbarcode: "1",
                        // smpregisterid: row.smp_registerid,
                        smpsampleid: row.smp_sampleid,
                        smpshelfposid: row.shelfposid,
                        preoutdate: this.preoutdate,
                    },
                });
                if (res.flag == "1") {
                    this.bLendBackVisible = false;
                    if (res.dtsmploc.length > 0) {
                        if (this.$refs.tree.getNode(row.locationid)) {
                            this.$refs.tree.getNode(row.locationid).data.name = res.dtsmploc[0].locationname + res.dtsmploc[0].occupypos;
                        }
                        if (flag == "1") {
                            this.$refs.tree.setCurrentKey(row.locationid);
                            var node = this.$refs.tree.getNode(row.locationid);
                            this.NodeClick("", node);
                        }
                    }
                    this.$message({
                        message: res.msg,
                        type: "success",
                    });
                } else if (res.flag == "0") {
                    this.$alert(res.msg, "提示:", { type: "error" });
                }
                this.HightlightPos(this.txtBarCode);
            } catch (e) {
                console.log("error", e);
                this.HightlightPos(this.txtBarCode);
            }
        },
        async scanBarcode() {
            if (this.bLastOk == false) {
                return false;
            }
            if (this.prepos.x == -1 || this.prepos.y == -1) {
                this.$alert("请选择正确的存放位置。", "提示:", { type: "error" });
                return false;
            }
            this.bLastOk = false;
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_labsample_in",
                        barcode: this.txtBarCode,
                        shelfid: this.shelfid,
                        allowrepeat: this.allowrepeat,
                        allowsendback: this.allowsendback,
                        posinrow: this.prepos.x,
                        posincol: this.prepos.y,
                        inorder: this.inorder,
                        locationid: this.locationid,
                        preoutdate: this.preoutdate,
                    },
                });
                if (res.flag == "1") {
                    console.log("🍐🦅🐟nextX", res.nextX);
                    console.log("🍐🦅🐟nextY", res.nextY);
                    this.bLendBackVisible = false;
                    this.locationDetail_Data = res.dt;
                    if (res.dtsmploc.length > 0) {
                        this.$refs.tree.getNode(this.locationid).data.name = res.dtsmploc[0].locationname + res.dtsmploc[0].occupypos;
                    }
                    // this.$refs.scaninput.focus();
                    //获取下一坐标，跳过之前的空位
                    this.shelfDetail[this.prepos.x - 1][this.prepos.y - 1].inuse = "2";
                    this.prepos = { x: res.nextX, y: res.nextY };
                    this.setNextPos();
                    // //设置下一焦点
                    // this.setNextPos();
                    //this.NodeClick("", this.tpNode);
                } else if (res.flag == "0") {
                    // res.keyid +
                    this.$alert(res.msg, "提示:", { type: "error" });
                    this.bLastOk = true;
                }
                this.HightlightPos(this.txtBarCode);
            } catch (e) {
                console.log("error", e);
                this.bLastOk = true;
                this.HightlightPos(this.txtBarCode);
            }
        },
        async btnQuery() {
            this.smpCnt = 0;
            this.bPlrkLoading = true;
            this.bSetLocOk = false;
            this.bIsLocDone = false;
            this.$tool
                .request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "smp_labsamplein_query",
                        ...this.searchobj,
                    },
                })
                .then((res) => {
                    if (res.RData.Data.length > 0) {
                        this.qLocData = res.RData.Data;
                        this.$refs.AtLocXTable.setCurrentRow(this.qLocData[0]);
                        this.oQLocData = XE.clone(res.RData.Data, true);
                        this.smpCnt = res.smpcnt;
                    } else {
                        this.qLocData = [];
                        this.oQLocData = [];
                        this.smpCnt = 0;
                    }
                    this.bPlrkLoading = false;
                    this.bInOk = false;
                })
                .catch((e) => {
                    this.smpCnt = 0;
                    this.bPlrkLoading = false;
                });
            // }
        },
        async btnQueryLendBack() {
            ////数据量应该不多 就不设loading了
            this.OtherShow = false;
            this.qlendbackdata = [];
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "queryLendBackLog",
                        librid: this.selLibrID,
                        lbstartdt: this.lbstartdt,
                        lbenddt: this.lbenddt,
                    },
                });
                if (res && res.length > 0) {
                    this.qlendbackdata = res;
                }
            } catch (e) {
                console.log("error", e);
            }
        },
        getCurrentData() {
            //用于更新删除、新增的数据   getCurrentNode 获取的是data getNode(key or data) 获取结点
            //   this.detailData = {};
            this.tpNode = this.$refs.tree.getNode(this.$refs.tree.getCurrentNode());
            this.prTpNode = this.$refs.tree.getNode(this.$refs.tree.getCurrentNode()).parent;
            //   this.fileclassid = this.$refs.tree.getCurrentNode().fileclassid;
        },
        async btnSetLoc() {
            var currentdata = this.$refs.tree.getCurrentNode();
            if (currentdata == null) {
                this.$alert("请先选择库位。", "提示:", { type: "error" });
                return false;
            }
            if (this.$refs.AtLocXTable.afterFullData.length < 1) {
                this.$alert("暂无可分配的库位数据，请重新查询。", "提示:", { type: "error" });
                return false;
            }
            if (currentdata.leaf == false) {
                this.$alert("当前库位不可放置样本架，请重新选择库位。", "提示:", { type: "error" });
                return false;
            }
            if (currentdata.name.indexOf("空:0") > -1) {
                this.$alert("当前架位已满，不可分配库位。", "提示:", { type: "error" });
                return false;
            }
            //库位名称可能含有判断的字符，这个判断放到后台的方法里。
            // if (this.skipnoempty == "1" && XE.toInteger(currentdata.name.slice(currentdata.name.indexOf("总") + 2, currentdata.name.indexOf("空") - 1)) > XE.toInteger(currentdata.name.slice(currentdata.name.indexOf("空") + 2, currentdata.name.indexOf(")")))) {
            //     this.$alert("选定库位已有标本，请重新选择。", "提示:", { type: "error" });
            //     return false;
            // }

            if (this.bInOk) {
                //控制分配成功后再分配库位
                this.$alert("成功分配入库，再次分配请先查询。", "提示:", { type: "error" });
                return false;
            }
            // if (currentdata.nativename != this.nowLocNa) {
            //     //校验当前库位是否正确
            //     this.$alert("当前库位存在异常,请重新选择左侧库位。", "提示:", { type: "error" });
            //     return false;
            // }
            this.qLocData = [];
            this.qLocData = JSON.parse(JSON.stringify(this.oQLocData));
            console.log("🍐🦅🐟 _ this.oQLocData", this.oQLocData);
            console.log("🍐🦅🐟 _ this.qLocData", this.qLocData[0]);
            this.bSetLocOk = false;
            this.bIsLocDone = false;
            this.bPlrkLoading = true;
            this.btnSetLoc1().then((res) => {
                setTimeout(() => {
                    this.bPlrkLoading = false;
                    if (res.flag == "1") {
                        //this.oQLocData = XE.clone(this.qLocData, true); //TODO 重复分配
                        // this.qLocData.forEach((e) => {
                        //     res.dataobj.forEach((rese) => {
                        //         if (e.reportid == rese.reportid) {
                        //             e.locationname = rese.locationname;
                        //             e.posincol = rese.posincol;
                        //             e.posinrow = rese.posinrow;
                        //             e.shelfid = rese.shelfid;
                        //             e.getloc = rese.getloc;
                        //         }
                        //     });
                        // });
                        for (var i = 0; i < this.qLocData.length; i++) {
                            for (var j = 0; j < res.dataobj.length; j++) {
                                if (this.qLocData[i].reportid == res.dataobj[j].reportid) {
                                    this.qLocData[i].locationname = res.dataobj[j].locationname;
                                    this.qLocData[i].posincol = res.dataobj[j].posincol;
                                    this.qLocData[i].posinrow = res.dataobj[j].posinrow;
                                    this.qLocData[i].shelfid = res.dataobj[j].shelfid;
                                    this.qLocData[i].getloc = res.dataobj[j].getloc;
                                }
                            }
                        }
                        console.log("🍐🦅🐟 _ this.qLocData", this.qLocData);
                        this.bIsLocDone = true;
                        this.$message({
                            message: res.msg,
                            type: "success",
                        });
                        this.bSetLocOk = true;
                        this.bIsLocDone = true;
                    } else if (res.flag == "0") {
                        this.$alert(res.msg, "提示", { type: "error" });
                    } else if (res.flag == "-1") {
                        this.$alert(res.msg, "提示", { type: "error" });
                    }
                    if (res.errcode == "0") {
                        this.$alert(res.errmsg, "提示", { type: "error" });
                    }
                });
            }, 6000);
        },
        btnSetLoc1() {
            return new Promise((s, f) => {
                this.$tool
                    .request({
                        url: "SMP/SMP2/SMP220",
                        method: "post",
                        data: {
                            action: "smp_labsamples_in_position",
                            locationid: this.locationid,
                            // posinrow:this.posinrow,
                            // posincol:this.posincol,
                            inorder: this.inorder,
                            skipnoempty: this.skipnoempty,
                            checkvalid: false, //TODO 暂不校验
                            datainfo: this.qLocData,
                        },
                    })
                    .then((res) => {
                        s(res);
                    })
                    .catch((e) => {
                        this.$alert(e, "提示", { type: "error" });
                        f();
                    });
            });
        },
        async btnLocSave() {
            var haveLocData = [];
            this.bInOk = false;
            this.$refs.AtLocXTable.afterFullData.forEach((e) => {
                if (e.locationname != "") {
                    haveLocData.push(e);
                }
            });
            const loading = this.$loading({
                // 声明一个loading对象
                lock: true, // 是否锁屏
                text: "正在批量入库,请稍后.....", // 加载动画的文字
                spinner: "el-icon-loading", // 引入的loading图标
                background: "rgba(0, 0, 0, 0.3)", // 背景颜色
                target: ".sub-main", // 需要遮罩的区域
                body: true,
                customClass: "mask", // 遮罩层新增类名
            });
            setTimeout(function () {
                // 设定定时器，超时20S后自动关闭遮罩层，避免请求失败时，遮罩层一直存在的问题
                loading.close(); // 关闭遮罩层
            }, 60000);
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_labsample_position_save",
                        allowrepeat: this.allowrepeat,
                        preoutdate: this.preoutdate,
                        checkvalid: false,
                        data: haveLocData,
                    },
                });
                if (res.flag == "1") {
                    this.$message.success(res.msg);
                    loading.close();
                    // this.$refs.tree.setCurrentKey(this.keyList[0]);
                    var node = this.$refs.tree.getNode(this.keyList[0]);
                    this.btnRefreshLoc(node).then(() => {
                        this.$refs.tree.setCurrentKey(this.locationid);
                        this.NodeClick("", this.$refs.tree.getNode(this.locationid));
                    });
                    this.bInOk = true;
                } else {
                    loading.close();
                    this.$alert(res.msg, "提示", { type: "error" });
                }
            } catch (e) {
                loading.close();
                this.$alert(e, "提示", { type: "error" });
            }
        },
        btnMoveAdd(object, Node, flag) {
            //新增，移入样本架
            //判断当前是否存在架子
            //不存在，根据类型弹出添加框 1新增 2删除 3移入 4移出
            if (flag == 1) {
                if (Node.data.name.indexOf("无") == -1) {
                    return false;
                }
                this.dlgShelfTitle = "新增样本架";
                this.action = "A";
                this.dlgMvShelfid = "";
                this.GetShelf();
            } else if (flag == 2) {
                this.action = "D";
                this.DelShelf();
                // this.dlgShelfTitle = "删除样本架"
                // this.bShelfDelVisible=true;
            } else if (flag == 3) {
                this.dlgShelfTitle = "移入样本架";
                this.action = "I";
                this.dlgMvShelfid = "";
                this.GetShelf();
            } else if (flag == 4) {
                this.action = "O";
                this.OutShelf();
                // this.dlgShelfTitle = "移出样本架"
                // this.bShelfDelVisible=true;
            }
        },
        //删除样本架 add2
        async DelShelf() {
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_shelf_del",
                        locationid: this.locationid,
                    },
                });
                if (res.flag == "1") {
                    this.$message.success("删除成功！" + res.msg);
                    //TODO 先用timeout  之后改promise
                    this.btnRefreshLoc(this.tpNode.parent);
                    setTimeout(() => {
                        this.$refs.tree.setCurrentKey(this.tpNode.data.locationid);
                        setTimeout(() => {
                            this.NodeClick("", this.tpNode);
                        }, 200);
                    }, 100);
                } else {
                    this.$message.error(res.msg);
                }
            } catch (e) {
                this.$message.error(e);
            }
        },
        //add4
        async OutShelf() {
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_shelf_out",
                        locationid: this.locationid,
                    },
                });
                if (res.flag == "1") {
                    //TODO 先用timeout  之后改promise
                    this.btnRefreshLoc(this.tpNode.parent);
                    setTimeout(() => {
                        this.$refs.tree.setCurrentKey(this.tpNode.data.locationid);
                        setTimeout(() => {
                            this.NodeClick("", this.tpNode);
                        }, 200);
                    }, 100);
                    this.$message.success("移出成功！" + res.msg);
                } else {
                    this.$message.error(res.msg);
                }
            } catch (e) {
                this.$message(e);
            }
        },
        async GetShelf() {
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP1/SMP133",
                    method: "post",
                    data: {
                        action: "smp_location_query_add_shelf_data",
                        locationid: this.locationid,
                        librid: this.selLibrID,
                    },
                });
                if (res.Data) {
                    if (res.Data[0].shelftype == "") {
                        this.$alert("当前位置未设置可放置架子类型。", "提示", {
                            confirmButtonText: "确定",
                            type: "error",
                        });
                        return false;
                    }
                    if (this.action == "A") {
                        this.bShelfAddVisible = true;
                        this.addShelf_Data = res.Data[0];
                    } else if (this.action == "I") {
                        this.bShelfAddVisible = true;
                    }
                    setTimeout(() => {
                        this.$refs.refMoveShelfid.focus();
                    }, 15);
                }
            } catch (e) {
                this.$message.error(e);
            }
        },
        btnMoveSave() {
            if (this.action == "A") {
                this.ShelfAddSave();
            } else if (this.action == "I") {
                this.ShelfInSave();
            }
        },
        async ShelfInSave() {
            try {
                if (!this.dlgShelfTitle) {
                    this.$alert("架子编号不能为空！");
                    return false;
                }
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_shelf_in",
                        locationid: this.locationid,
                        librid: this.selLibrID,
                        shelfno: this.dlgMvShelfid,
                    },
                });
                if (res.flag == "1") {
                    this.bShelfAddVisible = false;
                    this.$message.success("移入成功！" + res.msg);
                    //TODO 先用timeout  之后改promise
                    this.btnRefreshLoc(this.tpNode.parent);
                    setTimeout(() => {
                        this.$refs.tree.setCurrentKey(this.tpNode.data.locationid);
                        setTimeout(() => {
                            this.NodeClick("", this.tpNode);
                        }, 100);
                    }, 60);
                } else {
                    this.$message.error("移入失败:" + res.msg);
                }
            } catch (e) {
                this.$alert(e);
            }
        },
        //新增样本架right1
        async ShelfAddSave() {
            try {
                if ((this.shelfid = "")) {
                    this.$alert(
                        "请填写样本架ID",
                        "提示",
                        { type: "warning" },
                        {
                            confirmButtonText: "确定",
                        }
                    );
                    return false;
                }
                let gData = {
                    shelfid: null, //自动生成
                    librid: this.addShelf_Data.librid, //查询smp_location
                    shelftypeno: this.addShelf_Data.shelftype, //查询smp_location
                    shelfno: this.dlgMvShelfid, //手输数据
                    shelfdesc: "",
                    rownumber: this.addShelf_Data.rownumber, //需要查询样本架类型表
                    colnumber: this.addShelf_Data.colnumber, //需要查询样本架类型表
                    posnumber: this.addShelf_Data.posnumber, //需要查询样本架类型表
                    locationid: this.addShelf_Data.locationid, //X查询
                    usestatus: 0, //新增样本架为未使用的样本架
                    createuser: this.$tool.getSession(this.$tool.loginuserno),
                    createdt: this.$pub.InitDateTime(),
                };
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_shelf_add",
                        data: gData,
                        locationid: gData.locationid,
                        librid: gData.librid,
                        shelfno: gData.shelfno,
                    },
                });
                if (res.errcode == "1") {
                    this.$message({
                        message: "新增样本架成功！",
                        type: "success",
                    });
                    // this.dlgMvShelfid="";
                    this.shelfid = res.keyid;
                    this.bShelfAddVisible = false;
                    this.btnRefreshLoc(this.tpNode.parent);
                    //TODO 先用timeout  之后改promise
                    setTimeout(() => {
                        this.$refs.tree.setCurrentKey(this.tpNode.data.locationid);
                        setTimeout(() => {
                            this.NodeClick("", this.tpNode);
                        }, 200);
                    }, 100);
                } else {
                    this.$message({
                        message: res.msg,
                        type: "error",
                    });
                }
            } catch (e) {
                this.$alert(e);
            }
        },

        btnDelete() { },
        btnSave() { },
        btnCancel() { },
        btnPrint(index) {
            // dict打印
            // this.$pub.printDict(this, "SMP220 样本入库", this.$refs.AtLocXTable);
            if (typeof jsObj != "undefined") {
                let column = this.$refs.AtLocXTable.getTableColumn().tableColumn;
                let columns = this.$pub.InitColumn(column);
                let str = JSON.stringify(columns);
                str += "\r";
                str += JSON.stringify(this.qLocData);
                let sql = btoa(encodeURIComponent(str));
                if (this.qLocData.length > 0) {
                    if (index == "2") {
                        //设计
                        const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                        jsObj.SetCustomJsonPrintConfig("5053", sql, this.userno, "样本批量入库清单");
                        rload.close();
                    } else {
                        //打印
                        jsObj.PrintCustomJsonReport("5053", sql, this.userno, "样本批量入库清单", "");
                    }
                } else {
                    this.$alert("没有获取到数据！", "提示");
                }
            } else {
                this.$alert("请使用" + this.$pub.clientname + "打开！", "提示");
            }
        },
        btnLBPrint() {
            this.$pub.printDict(this, "SMP220 归还记录", this.$refs.qLendBackXTable);
        },
        btnExport() {
            //导出
            let tableColumn = this.$refs.AtLocXTable.getColumns();
            let extableColumn = [];
            tableColumn.forEach((item) => {
                extableColumn.push({ title: item.title, field: item.property });
            });
            this.$pub.exportTableExcel(this.qLocData, extableColumn, "SMP220 样本入库.xlsx");
        },
        handleClick() {
            this.plrkKey++;
            this.qlbKey++;
        },
        /*-----------------------------初始化-----------------------------*/
        //获取样本库列表
        ddlSmp_Library() {
            this.$tool
                .request({
                    url: "SMP/SMP1/SMP130",
                    method: "post",
                    data: {
                        action: "q_smp_library",
                        //islibrtype: "1",
                    },
                })
                .then((res) => {
                        this.selLibrID_Options = res;
                        // this.selLibrID = this.selLibrID_Options[0].librid;
                    this.SwitchTree();
                });
        },
        /*-----------------------------左侧树-----------------------------*/
        //点击事件
        NodeClick(data, node, key) {
            console.log("NodeClick这里加载数据", node)
            this.txtBarCode = "";
            this.preoutdate = "";
            this.nowLocNa = node.data.fulldata;
            //node.label 可以提取名称
            this.locationid = node.data.locationid;
            this.sampleInfo = {};
            this.shelfDetail = [];
            if (node.isLeaf) {
                this.getPreOutDate();
                this.GetChildTree(this.locationid, node);
            } else {
                // this.colData = [];
                // this.citem = [];
                // this.ritem = [];
                // this.rowData = [];
            }
            this.tpNode = node; //节点
            this.prTpNode = node.parent; //父节点
            // this.locationid = this.$refs.tree.getCurrentNode(node.children).locationid;去除右键直接新增报错
        },
        savepreoutdate() {
            var fulldata = this.$refs.locXTable.getTableData().fullData;
            if (fulldata.length > 0) {

                this.$tool
                    .request({
                        url: "SMP/SMP2/SMP220",
                        method: "post",
                        data: {
                            action: "smp_location_update_preoutdate",
                            data: fulldata,
                        },
                    })
                    .then((res) => {
                        if (res.flag == 1) {
                            this.$message.success("预设销毁日期成功。");
                        } else {
                            this.$message.error("预设销毁日期失败:" + res.msg);
                        }
                    }).catch((e) => {
                        console.log("error", e)
                    })
            }

        },
        batchsetpreoutdate() {
            if (!this.preoutdate) {
                this.$alert("未指定预设销毁日期。", "提示:", { type: "error" });
                return false;
            }
            var fulldata = this.$refs.locXTable.getTableData().fullData
            if (fulldata.length > 0) {
                fulldata.forEach((el) => {
                    el.preoutdate = this.preoutdate;
                })
            }
        },
        async getPreOutDate() {
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "getpreoutdate",
                        locationid: this.locationid,
                    },
                });
                if (res.length > 0) {
                    if (res[0].reservedays > 0) {
                        this.preoutdate = XE.toDateString(XE.getWhatDay(new Date(), XE.toInteger(res[0].reservedays)), "yyyy/MM/dd");
                    } else if ((res[0].reservedays = 0)) {
                        this.preoutdate = null;
                    }
                } else {
                    this.preoutdate = null;
                }
            } catch (e) { }
        },
        //懒加载
        async LoadNode(node, resolve) {
            console.log("LoadNode这里加载数据", node, resolve)
            //展开第一级节点，从后台加载一级节点列表
            if (node.level == 0) {
                this.node_had = node;
                this.resolve_had = resolve;
                var data = await this.GetFatherTree(this.selLibrID, this.locationid);
                return resolve(data);
            } else if (node.level >= 1) {
                //展开其他子节点，动态从后台加载下一级节点列表
                var data = await this.GetChildTree(node.data.locationid, node);
                if (data.length == 0) {
                    //!node.leaf = true;
                    node.leaf = false;
                    node.icon = "el-icon-document-copy";
                }
                return resolve(data);
            }
        },
        //选择对应样本库的树
        SwitchTree() {
            this.locationid = -1;
            this.node_had.childNodes = []; //把存起来的node的子节点清空，避免出现重复树.
            this.LoadNode(this.node_had, this.resolve_had); //再次执行懒加载的方法,载入新的树节点
            this.getlocationList();
        },
        //获取locationid
        async getlocationList() {
            this.locationList = [];
            this.keyList = [];
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "getlocationList",
                        librid: this.selLibrID,
                    },
                });
                if (res.dt.length > 0) {
                    this.locationList = res.dt;
                    res.dt.forEach((e) => {
                        this.keyList.push(e.locationid);
                    });
                    this.maxlv = res.maxlevel[0].maxlv;
                } else {
                    this.locationList = [];
                    this.maxlv = 0;
                }
                this.HightlightPos(this.txtBarCode);
            } catch (e) {
                console.log("error", e);
                this.HightlightPos(this.txtBarCode);
            }
        },
        //重新加载子节点
        btnRefreshLoc(node) {
            return new Promise((s, f) => {
                node.loaded = false;
                node.expand(); //主动调用展开节点方法，重新查询该节点下的所有子节点
                s();
            });
        },
        //父节点:加载第一级节点
        async GetFatherTree() {
            this.nowLocNa = ""; //清空位置名称,避免切换库时遇到空库
            try {
                let tempNode = [];
                const res = await this.$tool.request({
                    url: "SMP/SMP1/SMP133",
                    method: "post",
                    data: {
                        action: "smp_location_query",
                        librid: this.selLibrID,
                        locationid: this.locationid,
                    },
                });
                if (res.RData.Data) {
                    res.RData.Data.forEach((item) => {
                        // node {}->data {}
                        let data = {};
                        data.nativename = item.locationname; //用于移架msg
                        data.fulldata = item.locationname + "(" + item.locationcode + ")";
                        data.name = item.locationname + item.occupypos;
                        data.locationid = item.locationid;
                        data.shelfid = ""; // 冗余 也放着吧 避免缺少字段
                        data.icon = "el-icon-house";
                        data.parentid = item.parentlocid; //获取parentid
                        tempNode.push(data);
                        this.nowLocNa = data.fulldata; //初始化树时获取根节点name 
                        this.fatherLocId = item.locationid;
                    });
                }
                return tempNode;
            } catch (e) {
                this.$message.warning(e.message);
            }
        },
        //子节点:每次加载下一级子节点 btnquery
        async GetChildTree(locationid, Node) {
            try {
                let tempNode = [];
                this.locationDetail_Data = [];
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_location_query_childinfo",
                        librid: this.selLibrID,
                        locationid: locationid,
                    },
                });
                if (res.shelflag == "1") {
                    res.RData.Data.forEach((item) => {
                        let node = {};
                        node.nativename = item.locationname;
                        node.fulldata = item.locationname + "(" + item.locationcode + ")";
                        node.name = item.locationname + item.occupypos;
                        node.locationid = item.locationid;
                        node.leaf = false;
                        node.parentid = item.parentlocid; // 获取parentid
                        node.rownumber = res.rownumber; // 先存一份在data
                        node.colnumber = res.colnumber;

                        if (item.lastflag == 0) {
                            if (Node.level == 1) node.icon = "el-icon-mobile";
                            if (Node.level == 2) node.icon = "el-icon-document";
                            if (Node.level == 3) node.icon = "el-icon-tickets";
                            if (Node.level == 4) node.icon = "el-icon-receiving";
                            if (Node.level == 5) node.icon = "el-icon-bangzhu";
                        } else {
                            node.icon = "el-icon-place";
                            node.leaf = true;
                            node.shelfid = item.shelfid; //获取样本架ID
                        }
                        tempNode.push(node);
                    });
                    if (res.RSample.Data.length > 0) {
                        //TODO 添加样本架图案
                        this.locationDetail_Data = res.RSample.Data;
                        this.$refs.locXTable.setCurrentRow(this.locationDetail_Data[0]);
                        this.sampleInfo = this.locationDetail_Data[0];
                    }
                    if (res.shelflag == "1") {
                        // if (res.RShelf.Data.length > 0) {
                        var shelfDetail = new Array(res.rownumber);
                        for (var m = 0; m < res.rownumber; m++) {
                            shelfDetail[m] = new Array(res.colnumber);
                            for (var n = 0; n < res.colnumber; n++) {
                                shelfDetail[m][n] = {
                                    inuse: "0",
                                    isselected: false,
                                };
                            }
                        }
                        res.RSample.Data.forEach((element) => {
                            shelfDetail[element.posinrow - 1][element.posincol - 1] = {
                                inuse: element.inuse,
                                isselected: false,
                            };
                        });
                        console.log("shelfDetail", shelfDetail);
                        this.shelfDetail = shelfDetail;
                        this.selectrow = {
                            rownumber: res.rownumber,
                            colnumber: res.colnumber,
                        };
                    }
                    this.FocusNextPos();
                } else {
                    this.shelfDetail = [];
                    this.selectrow = {
                        rownumber: 0,
                        colnumber: 0,
                    };
                }
                // }
                if (res.lastflag == "1") {
                    if (res.havesheild == "1") {
                        this.shelfid = res.shelfid;
                    }
                }
                return tempNode;
            } catch (e) {
                this.$message.warning(e.message);
            }
        },
        //右键菜单
        RightClick(e, object, Node, element) {
            this.locationid = object.locationid;
            this.NodeClick("", Node);
            this.$refs.tree.setCurrentKey(Node.data.locationid);
            this.$tool
                .request({
                    url: "SMP/SMP1/SMP133",
                    method: "post",
                    data: {
                        action: "smp_location_query_islastflag",
                        locationid: object.locationid,
                        librid: this.selLibrID,
                    },
                })
                .then((res) => {
                    let data = res.dt;
                    this.isLast = XE.toInteger(res.Data[0].lastflag);
                    let isA = false;
                    let isD = false;
                    let isI = false;
                    let isO = false;
                    let bFLastOne = false;
                    if (this.isLast == 0) {
                        bFLastOne = true;
                    } else {
                        bFLastOne = false;
                    }
                    this.tpNode = Node; //节点
                    this.prTpNode = Node.parent; //父节点
                    //?判断显示逻辑 前台控制右键按钮
                    if (this.tpNode.data.name.indexOf("无") > -1) {
                        //无架
                        isD = true;
                        isO = true;
                    }
                    if (this.tpNode.data.name.indexOf("总") > -1) {
                        var sum = XE.toInteger(this.tpNode.data.name.slice(this.tpNode.data.name.indexOf("总") + 2, this.tpNode.data.name.indexOf("空") - 1));
                        var current = XE.toInteger(this.tpNode.data.name.slice(this.tpNode.data.name.indexOf("空") + 2, this.tpNode.data.name.indexOf(")")));
                        if (sum > current) {
                            isO = true;
                            isD = true;
                        }
                        isA = true;
                        isI = true;
                    }
                    this.$contextmenu({
                        items: [
                            {
                                label: "重新读取",
                                onClick: () => {
                                    this.btnRefreshLoc(Node);
                                },
                                icon: "el-icon-refresh",
                                hidden: !bFLastOne, //修复最后一级结点重新读取显示BUG
                            },
                            // { divided: true, hidden: bFLastOne },
                            {
                                label: "新增样本架",
                                onClick: () => {
                                    this.btnMoveAdd(object, Node, 1);
                                },
                                icon: "el-icon-plus",
                                disabled: isA,
                                hidden: bFLastOne,
                            },
                            {
                                label: "删除样本架",
                                onClick: () => {
                                    this.btnMoveAdd(object, Node, 2);
                                },
                                icon: "el-icon-minus",
                                divided: true, //分割模块
                                disabled: isD,
                                hidden: bFLastOne,
                            },
                            {
                                label: "移入样本架",
                                onClick: () => {
                                    this.btnMoveAdd(object, Node, 3);
                                },
                                icon: "el-icon-right",
                                disabled: isI,
                                hidden: bFLastOne,
                            },
                            {
                                label: "移出样本架",
                                onClick: () => {
                                    this.btnMoveAdd(object, Node, 4);
                                },
                                icon: "el-icon-back",
                                divided: true,
                                disabled: isO,
                                hidden: bFLastOne,
                            },
                            { divided: true, hidden: bFLastOne },
                            {
                                label: "使用帮助",
                                onClick: () => {
                                    this.bHelpViible = true;
                                },
                                icon: "el-icon-thumb",
                                divided: true,
                                hidden: bFLastOne,
                            },
                        ],
                        e,
                        x: e.clientX + 20,
                        y: e.clientY,
                        customClass: "RightBack",
                        zIndex: 999,
                        minWidth: 120,
                        customClass: "background-color: #f8f8f8;border-bottom:solid 1px #e6e6e6",
                    });
                    this.isLast = "0";
                })
                .catch((e) => {
                    console.log("error", e);
                });
        },
        //允许拖拽
        allowDrag(draggingNode, dropNode) {
            //添加非空架子禁止拖拽
            // return draggingNode.data.leaf; 
            if (draggingNode.data.leaf == true) {
                if (!(draggingNode.data.name.indexOf("无") > -1)) {
                    return true;
                }
            }
            return false;
        },
        //允许放置： 只允许放置在有架位上
        allowDrop(draggingNode, dropNode) {
            if (dropNode.data.leaf == true) return true;
            else return false;
        },
        //节点开始拖拽时触发的事件
        nodeDragStart(Node, event) {
            // if (Node.data.leaf == false||(Node.data.name.indexOf("无")>-1)) {
            //     return false;
            // }
        },
        //节点拖拽结束时触发的事件
        nodeDragEnd(draggingNode, dropNode, dropType, ev) { },
        nodeDrop(draggingNode, dropNode, dropType, ev) {
            if (dropNode.data.leaf == false) {
                // return false;
                this.btnRefreshLoc(draggingNode.parent);
                this.btnRefreshLoc(dropNode.parent);
            }
            this.$confirm("将<b style='color:blue'>" + draggingNode.data.nativename + "</b>上的<b style='color:blue'>" + "架子:" + draggingNode.data.shelfid + "</b> 移动至<b style='color:blue'>" + dropNode.data.nativename + "</b>吗？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
                dangerouslyUseHTMLString: true,
            })
                .then(() => {
                    this.MoveClass(draggingNode, dropNode);
                })
                .catch((e) => {
                    var parentnode = this.$refs.tree.getNode(draggingNode.data.parentid);
                    this.btnRefreshLoc(parentnode);
                    this.btnRefreshLoc(dropNode.parent);
                    //TODO 暂时先用settimeout 之后需要改成promise
                    setTimeout(() => {
                        // this.NodeClick("", this.tpNode);
                        this.$refs.tree.setCurrentKey(this.tpNode.data.locationid);
                        setTimeout(() => {
                            this.NodeClick("", this.tpNode);
                        }, 200);
                    }, 100);
                });
        },
        async MoveClass(draggingNode, dropNode) {
            var parentnode = this.$refs.tree.getNode(draggingNode.data.parentid);
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "smp_sampleshelf_move",
                        shelfid: draggingNode.data.shelfid,
                        newlocationid: dropNode.data.locationid,
                    },
                });
                if (res.flag == "0") {
                    this.$alert("移动失败:" + res.msg, "提示", { type: "error" }, { confirmButtonText: "确定" });
                    this.btnRefreshLoc(parentnode);
                    this.btnRefreshLoc(dropNode.parent);
                    setTimeout(() => {
                        this.$refs.tree.setCurrentKey(draggingNode.data.locationid);
                        setTimeout(() => {
                            this.NodeClick("", draggingNode);
                        }, 200);
                    }, 100);
                } else {
                    this.btnRefreshLoc(parentnode);
                    this.btnRefreshLoc(dropNode.parent);
                    setTimeout(() => {
                        this.$refs.tree.setCurrentKey(dropNode.data.locationid);
                        setTimeout(() => {
                            this.NodeClick("", dropNode);
                        }, 200);
                    }, 100);
                }
            } catch (e) {
                this.btnRefreshLoc(parentnode);
                this.btnRefreshLoc(dropNode.parent);
                setTimeout(() => {
                    this.$refs.tree.setCurrentKey(this.tpNode.data.locationid);
                    setTimeout(() => {
                        this.NodeClick("", this.tpNode);
                    }, 200);
                }, 100);
                this.$message.warning(e.msg);
            }
        },
        //节点图标
        RenderContent(h, { node, data, store }) {
            return (
                <span>
                    <i class={data.icon}></i>
                    <span> {node.label}</span>
                </span>
            );
        },
        /*-----------------------------查询条件-----------------------------*/
        popMultipleChk(e, fieldname, option, title) {
            let temp = XE.clone(option, true);
            this.option1 = [];
            this.option2 = [];
            if (e != "") {
                let k = e.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.option2.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.option1.push(item);
                    }
                });
            } else {
                this.option1 = temp;
            }
            this.fieldname = fieldname;
            this.multichktitle = title;
            this.bDlgMultiple = true;
        },

        closedialog(value, name) {
            if (value != "close") {
                this.searchobj[name] = value;
            }
            this.bDlgMultiple = false;
        },
        async initOption() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS6/LIS610",
                    method: "post",
                    data: {
                        action: "initOption",
                    },
                });
                this.pattypeOption = res.pattypeOption;
                this.deptOption = res.deptOption;
                this.hospOption = res.hospOption;
                this.doctorOption = res.doctorOption;
                this.rptunitOption = res.rptunitOption;
                this.rptunitGroupOption = res.rptunitGroupOption;
                this.reportcommOption = res.reportcommOption;
                this.wardOption = res.wardOption;
                this.labgroupOption = res.labgroupOption;
                this.specimenOption = res.specimenOption;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        /*-----------------------------按钮类-----------------------------*/
        async GetSmpTree() {
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "getsmptree",
                    },
                });
                this.smptree_Data = res.Data[0];
            } catch (e) {
                this.$$message.warning(e);
            }
        },
        async ShowNullShlef() {
            try {
                const res = await this.$tool.request({
                    url: "SMP/SMP2/SMP220",
                    method: "post",
                    data: {
                        action: "GetNullShelf",
                        librid: this.selLibrID,
                        locationid: this.locationid,
                    },
                });
                this.bNullShelfVisible = true;
                if (res) {
                    this.nullShelf_Data = res;
                } else {
                    this.$message.error(e);
                }
            } catch (e) {
                this.$message.error(e);
            }
        },
        nullShelf_Click(row) {
            this.dlgMvShelfid = row.shelfno;
        },
        tabchange(index, hiscode) {
            this.tabindexlist = [index];
            switch (index) {
                case "2":
                    this.tab_jkffmx_getdata(hiscode);
                    break;
            }
        },
        tab_getdata(tab, event) {
            if (tab.label == "扫描入库") {
                this.tabindex = "1";
                if (this.tabindexlist.indexOf("1") <= -1) this.tabindexlist.push("1");
            }
            if (tab.label == "批量入库") {
                this.tabindex = "2";
                if (this.tabindexlist.indexOf("2") <= -1) {
                    this.tabindexlist.push("2");
                    this.tab_plrk_getdata(this.his_interface_info_B.his_code);
                }
            }
        },
        treeCurrentChangeEvent(data, node) { },
        smrkCurrentChangeEvent({ row }) {
            this.$refs.locXTable.clearCurrentRow().then(() => {
                this.$refs.locXTable.setCurrentRow(row);
                this.sampleInfo = row;
                this.prepos = { x: this.sampleInfo.posinrow, y: this.sampleInfo.posincol };
                this.setNextPos();
            });
        },
        plrkCurrentChangeEvent({ row, rowIndex }) { },
        //添加 扫描入库TAB页下 VXETable 单元格css
        smrkCellClassName({ columnIndex, column, row }) {
            if (column.property === "quantitystatus") {
                if (row.quantitystatus == "正常") {
                    return "quantitystatus_normal";
                } else if (row.quantitystatus == "少量") {
                    return "quantitystatus_little";
                }
            }
            if (column.property === "preoutdate") {
                // var now = this.$pub.InitDateTime();
                // if (row.preoutdate.getTime() < this.$pub.InitDateTime().getTime()) {
                //     return "quantitystatus_little";
                // } else {
                //     return "quantitystatus_normal";
                // }
            }
        },
        plrkCellClassName({ columnIndex, column, row }) {
            if (row.getloc == "1" && (column.property === "posinrow" || column.property === "posincol" || column.property === "locationname")) {
                return "color_getloc";
            }
        },
    },
};
</script>

<style scoped>
.left {
    left: 0px;
    height: 100%;
    border: 1px solid #ccc;
}

.right {
    right: 0px;
    height: 100%;
}

.right-top {
    position: absolute;
    width: 100%;
    height: 38px;
    background-color: powderblue;
    border: 1px solid #ccc;
    overflow-x: auto;
    white-space: nowrap;
}

.right-center {
    position: absolute;
    width: 100%;
    top: 43px;
    bottom: 0px;
    background-color: yellowgreen;
}

.right-center-smrk-1 {
    width: 100%;
    height: 38px;
    border: 1px solid #ccc;
    overflow-x: auto;
    white-space: nowrap;
}

.right-center-smrk-2 {
    position: absolute;
    width: 100%;
    top: 43px;
    height: 260px;
    border: 1px solid #ccc;
}

.right-center-smrk-2-row {
    float: left;
    left: 32px;
    width: calc(100% - 30px);
    height: 30px;
}

.right-center-smrk-3 {
    position: absolute;
    width: 100%;
    top: 305px;
    bottom: 0px;
    border: 1px solid #ccc;
}

.right-center-plrk-ly-1 {
    width: 100%;
    height: 133px;
    border: 1px solid #ccc;
    position: absolute;
    overflow: auto;
    white-space: nowrap;
}

.right-center-plrk-ly-2 {
    position: absolute;
    height: calc(100% - 135px);
    width: 100%;
    top: 137px;
    bottom: 0px;
    overflow: "auto";
    /* border: 1px solid #ccc; */
}

table {
    font-size: 12px;
    border-spacing: 5px;
}

.maintab {
    width: 100%;
    table-layout: fixed;
    word-break: break-all;
}

.maintab td {
    height: 20px;
}

.table1style tr td {
    padding: 0px 2px 0px 5px;
    -webkit-box-pack: center;
    -webkit-box-align: center;
}

.lendbacktab-top {
    position: absolute;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
}

.lendbacktab-center {
    position: absolute;
    /* height:calc(100% - 115px); */
    width: 100%;
    bottom: 0px;
    overflow: auto;
}

.table2style tr td {
    align: center;
    white-space: nowrap;
    padding: 0 0 0 5px;
    -webkit-box-pack: center;
    -webkit-box-align: center;
}

::v-deep .table2style .el-input--prefix .el-input__inner {
    padding-left: 5px;
}

.el-tree {
    min-width: 100%;
    font-size: 14px;
    display: inline-block;
}

.tree {
    overflow-y: auto;
    overflow-x: scroll;
    height: 100%;
    border: 1px solid grey;
}

.colordiv1 {
    background-color: rgb(28, 195, 224);
    white-space: nowrap;
}

.instrument {
    text-align: center;
    pointer-events: none;
    font-size: 10px;
}

::v-deep .vxe-table .vxe-body--column.col-orange {
    background-color: #f8f8f8;
}

::v-deep .el-dialog__body {
    padding: 0px 20px 5px 20px;
    color: #606266;
    font-size: 14px;
    word-break: break-all;
}

::v-deep .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
    background-color: #b6e8ff;
    color: #000000;
    font-weight: 700;
}

/* 去除 时间选择器右侧padding*/
::v-deep .el-input--suffix .el-input__inner {
    padding-right: 0px !important;
}

::v-deep .el-checkbox__label {
    padding-left: 3px;
    font-size: 12px !important;
}

::v-deep .el-divider--horizontal {
    display: block;
    height: 1px;
    width: 100%;
    margin: 5px 0;
}

::v-deep .vxe-table .vxe-cell {
    white-space: normal;
    word-break: break-word;
    padding: 0 5px;
}

::v-deep .color_getloc {
    background-color: #0099ff !important;
    color: white !important;
    font-weight: 600;
}

::v-deep tr.vxe-body--row.row--current {
    color: #000000;
    font-weight: bold;
}

/* 位移线条修改 */
::v-deep .el-tree__drop-indicator {
    position: absolute;
    left: 0;
    right: 0;
    height: 0px;
}

/** el-tree选中行 深蓝
   提亮树组件行颜色*/
::v-deep .el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
    background-color: #4dc0f5 !important;
}

/** el-tree点击 浅蓝
    提亮树组件行颜色
     还是要降低一些颜色 避免相临行点击按下区分不出来*/
::v-deep .el-tree-node:focus>.el-tree-node__content {
    background-color: #8fd5f5 !important;
}

/* el-tree鼠标悬停 蓝白
  提亮树组件行颜色*/
::v-deep .el-tree-node__content:hover {
    background-color: #dbf3ff;
}

/** 去除多余padding,尽量节约左侧树控件空间 */
::v-deep .el-tree-node__content>.el-tree-node__expand-icon {
    padding: 0px;
}

/** vxe-table选中行颜色也加深下吧,和左侧树状保持一致 */
::v-deep .vxe-table .vxe-body--row.row--current td {
    background-color: #4dc0f5 !important;
}

.show-text {
    border-bottom: 1px solid #cccccc;
}

/**扫描入库 右侧病人信息 */
.sample-content {
    /* margin-top: 10px; */
    width: 100%;
    height: 100%;
    border: 1px solid #cccccc;
}

.sample-content div {
    padding: 0px 0;
    font-size: 12px;
}

.sample-infodata div {
    white-space: nowrap;
    /* overflow: auto; */
}

.sample-content span {
    display: inline-block;
    text-align: left;
}

.sample-content span:nth-child(odd) {
    text-align: right;
}

.sample-title {
    width: 60px;
    padding: 3px 0 0px 10px;
    /* white-space: nowrap; */
}

.sample-info {
    width: 112px;
    border-bottom: #cccccc solid 1px;
    padding: 3px 0 1px 0;
}

.sample-info1 {
    width: 28px;
    border-bottom: #cccccc solid 1px;
    padding: 0 0 3px 0;
}

/**
    样本量状态-正常
 */
::v-deep .quantitystatus_normal {
    color: #006400;
}

/**
    样本量状态-少量
 */
::v-deep .quantitystatus_little {
    /* color:Firebrick2 */
    color: #ee2c2c;
}

::v-deep .sample-info .el-textarea__inner {
    padding: 0;
    margin: 0;
    border: 0;
}

/**
disabled不显示颜色 
去除 cursor,上面都没有 这个也不要有了吧，用来复制带个禁止logo比较奇怪 
 */
::v-deep .el-textarea.is-disabled .el-textarea__inner {
    color: #000 !important;
    background-color: #fff !important;
    cursor: default !important;
}

/**
样本扫描入库图案
*/
.shelf-detail {
    /* margin-left: 20px; */
    width: 100%;
    height: 100%;
    border: 1px solid #cccccc;
    overflow: auto;
}

.shelf-row {
    height: 20px;
}

.first-row {
    height: 43px;
}

/* 用于拖动去除全选、拖拽... */
.row-title {
    width: 18px;
    text-align: center;
    line-height: 15px;
    font-size: 12px;
    margin: 0 2px;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    -khtml-user-select: none;
    user-select: none;
}

.col-title {
    display: inline-table;
    width: 19px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    font-size: 12px;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    -khtml-user-select: none;
    user-select: none;
}

.shelf-position {
    height: 15px;
    width: 15px;
    background-color: #ffffff;
    border: 1px solid #818181;
    border-radius: 50%;
    margin: 0 2px;
}

.shelf-inuse {
    background-color: rgb(166, 235, 173);
}

/* 居中 */
.shelf-inuse-focus {
    height: 17px;
    width: 17px;
    border: 1px solid #818181;
    /* background-color: rgb(52, 214, 66); */
    /* border: 9px solid rgb(52, 214, 66); */
    border-style: double;
    background-color: rgb(231, 255, 233);
    margin: 0 0px;
}

.shelf-unuse-focus {
    /* background-color: rgb(52, 214, 66); */
    height: 17px;
    width: 17px;
    /* border: 2px solid #2ee7ff; */
    background-color: #eef895;
    border: 1px solid #818181;
}

.nofirst-row {
    display: inline-flex;
}

.poppagetop {
    float: right;
    width: 100%;
    height: 24px;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    position: absolute;
    /* border: 1px solid #ccc; */
    z-index: 999;
}

.poppagecenter {
    position: absolute;
    overflow: auto;
    top: 27px;
    width: 100%;
    height: 300px;
    left: 0;
}

/* * { background-color: rgba(255,0,0,.2); }
    * * { background-color: rgba(0,255,0,.2); }
    * * * { background-color: rgba(0,0,255,.2); }
    * * * * { background-color: rgba(255,0,255,.2); }
    * * * * * { background-color: rgba(0,255,255,.2); }
    * * * * * * { background-color: rgba(255,255,0,.2); } */</style>